﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CarShopManagerBLL;
using Model;

namespace CarShopManagerWeb
{
    public partial class Order : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShowCarInfo();
            }
        }
       //1:显示车辆信息（根据车辆编号查询车辆信息，并显示到页面对应的lable标签上）
        public void ShowCarInfo()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            DataTable dt = CarInfoBLL.GetCarInfoById(id);
            LabCarId.Text = dt.Rows[0]["Id"].ToString();
            LabCarName.Text = dt.Rows[0]["Name"].ToString();
            LabGuidePrice.Text = dt.Rows[0]["GuidePrice"].ToString();
            LabSellingPrice.Text = dt.Rows[0]["SellingPrice"].ToString();
        }
        
        protected void btnOK_Click(object sender, EventArgs e)
        {
            //获取上个页面传递来的车辆编号
            int id=Convert.ToInt32(Request.QueryString["id"]);
            //2:添加客户信息（向客户预定表中添加客户预定信息）
            //创建客户预定对象
            CarClient c = new CarClient();
            c.CarId = id;
            c.Deposit =Convert.ToDecimal(txtDeposit.Text.Trim());
            c.Mobile = txtTel.Text.Trim();
            c.Name = txtClientName.Text.Trim();
            c.Sex = Convert.ToBoolean(RDBSex.SelectedValue);
            int r = CarClientBLL.AddCarClientInfo(c);
            if (r > 0)
            {
                //3:更新车辆的状态和销售日期（根据上个页面中传递来的id修改该车辆状态和销售日期）
                int s = CarInfoBLL.UpdateCarInfo(id);
                if (s > 0)
                {
                    Response.Write("<script>alert('客户信息添加成功！');location.href='Index.aspx';</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('客户信息添加失败！');</script>");
            }
            
        }
    }
}